<template>
  <div class="box">
    <div class="header">
      <div class="left">
        <span>3.9</span>
        <span>综合评分</span>
        <span>高于周边商家69.2%</span>
      </div>
      <div>
        <div class="right">
          <div>
            <span>服务态度</span>
            <div class="star">
              <img src="./img/star36_on@2x.png" alt="" />
              <img src="./img/star36_on@2x.png" alt="" />
              <img src="./img/star36_on@2x.png" alt="" />
              <img src="./img/star36_on@2x.png" alt="" />
              <img src="./img/star36_on@2x.png" alt="" />
            </div>
            <span class="score"> 3.9 </span>
          </div>
          <div>
            <span>服务态度</span>
            <div class="star">
              <img src="./img/star36_on@2x.png" alt="" />
              <img src="./img/star36_on@2x.png" alt="" />
              <img src="./img/star36_on@2x.png" alt="" />
              <img src="./img/star36_on@2x.png" alt="" />
              <img src="./img/star36_on@2x.png" alt="" />
            </div>
            <span class="score"> 4.1 </span>
          </div>
          <div>
            <span>送达时间</span>
            <span>44分钟</span>
          </div>
        </div>
      </div>
    </div>
    <div class="comments">
      <div class="btns">
        <div class="btn1" @click="judge1(2)">
          <span>全部</span>
          <span class="num">56</span>
        </div>
        <div class="btn2" @click="judge1(0)">
          <span>满意</span>
          <span class="num">47</span>
        </div>
        <div class="btn3" @click="judge1(1)">
          <span>不满意</span>
          <span class="num">10</span>
        </div>
      </div>
      <div class="choose-tab" @click="judge2()">
        <i class="iconfont icon-duihao2"></i>
        <span>只看评价内容</span>
      </div>
      <div class="choose"></div>
    </div>
    <div class="userComments" v-for="(item, index) in rating" :key="index">
      <div class="user">
        <img :src="item.avatar" alt="" />
        <div>
          <div>
            <span>{{ item.username }}</span>
            <span class="time">{{ item.rateTime | formatDate }}</span>
          </div>
          <span>
            <div class="star">
              <img
                v-for="(item, index) in item.score"
                :key="index"
                src="./img/star36_on@2x.png"
                alt=""
              />
              <img
                v-for="(item, index) in 5 - item.score"
                :key="index + 'a'"
                src="./img/star36_off@2x.png"
                alt=""
              />
            </div>
            <span v-if="item.deliveryTime"
              >{{ item.deliveryTime }}分钟送达</span
            >
          </span>
        </div>
      </div>
      <p class="user-comments">
        {{ item.text }}
      </p>
      <div class="praise">
        <i
          :class="item.rateType ? 'a' : ''"
          class="iconfont icon-like-fill"
        ></i>
        <span class="tag" v-for="(num, index) in item.recommend" :key="index">{{
          num
        }}</span>
      </div>
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";
export default {
  name: "Evaluation",
  components: {},
  data() {
    return {
      obj: { evaluation: 2, isNull: false },
    };
  },
  filters: {
    formatDate: function (value) {
      let date = new Date(value);
      let y = date.getFullYear();
      let MM = date.getMonth() + 1;
      MM = MM < 10 ? "0" + MM : MM;
      let d = date.getDate();
      d = d < 10 ? "0" + d : d;
      let h = date.getHours();
      h = h < 10 ? "0" + h : h;
      let m = date.getMinutes();
      m = m < 10 ? "0" + m : m;
      let s = date.getSeconds();
      s = s < 10 ? "0" + s : s;
      return y + "-" + MM + "-" + d + " " + h + ":" + m + ":" + s;
    },
  },
  watch: {
    obj: {
      handler(newName, oldName) {
        console.log(newName);
        this.$store.commit("judge",this.obj);
      },
      deep: true,
      immediate: true,
    },
  },
  mounted() {
    this.getRatingsList();
  },
  methods: {
    judge1(a) {
      this.obj.evaluation = a
      // this.$set(this.obj, "evaluation", a);
    },
    judge2() {
      this.obj.isNull = !this.obj.isNull
      // this.$set(this.obj, "isNull", b);
    },
    getRatingsList() {
      this.$store.dispatch("getRatingsList");
    },
  },
  computed: {
    ...mapState({
      rating:state=>state.ratings.rating
    }),
  },
};
</script>
<style lang="less"scoped>
.box {
  margin-top: 2px;
  background-color: #eee;
  .header {
    background-color: #fff;
    padding: 36px 0;
    display: flex;
    border-bottom: 2px solid rgba(7, 17, 27, 0.1);
    .left {
      padding: 0 36px;
      & > :nth-child(1) {
        text-align: center;
        display: block;
        font-size: 48px;
        color: rgb(255, 153, 0);
        line-height: 56px;
      }
      & > :nth-child(2) {
        text-align: center;
        font-size: 24px;
        color: rgb(7, 17, 27);
        line-height: 24px;
        display: block;
        margin: 12px 0 16px;
      }
      & > :nth-child(3) {
        text-align: center;
        display: block;
        font-size: 20px;
        color: rgb(147, 153, 159);
        line-height: 20px;
      }
    }
    .right {
      padding-left: 48px;
      border-left: 1px solid rgba(7, 17, 27, 0.1);
      & > :nth-child(1) {
        & > :nth-child(1) {
          font-size: 24px;
          color: rgb(7, 17, 27);
          line-height: 36px;
        }
        & > :nth-child(2) {
          display: inline-block;
          margin-left: 12px;
          margin-right: 24px;
          img {
            display: inline-block;
            margin-left: 12px;
            padding: 0;
            width: 24px;
            height: 24px;
          }
        }
        & > :nth-child(3) {
          font-size: 24px;
          color: rgb(255, 153, 0);
          line-height: 36px;
        }
      }
      & > :nth-child(2) {
        margin: 16px 0;
        & > :nth-child(1) {
          font-size: 24px;
          color: rgb(7, 17, 27);
          line-height: 36px;
        }
        & > :nth-child(2) {
          display: inline-block;
          margin-left: 12px;
          margin-right: 24px;
          img {
            display: inline-block;
            margin-left: 12px;
            padding: 0;
            width: 24px;
            height: 24px;
          }
        }
        & > :nth-child(3) {
          font-size: 24px;
          color: rgb(255, 153, 0);
          line-height: 36px;
        }
      }
      & > :nth-child(3) {
        & > :nth-child(1) {
          display: inline-block;
          margin-right: 24px;
          font-size: 24px;
          color: rgb(7, 17, 27);
          line-height: 36px;
        }
        & > :nth-child(2) {
          font-size: 24px;
          color: rgb(147, 153, 159);
          line-height: 36px;
        }
      }
    }
  }
  .comments {
    background-color: #fff;
    margin-top: 36px;
    border-top: 1px solid rgba(7, 17, 27, 0.1);
    border-bottom: 1px solid rgba(7, 17, 27, 0.1);
    padding: 0 36px;
    .btns {
      border-bottom: 1px solid rgba(7, 17, 27, 0.1);
      padding: 36px 0;
      .btn1 {
        box-sizing: border-box;
        margin-right: 18px;
        display: inline-block;
        background-color: #00a0dc;
        padding: 18px 21px;
        border-radius: 10px;
        height: 65px;
        & > :nth-child(1) {
          display: inline-block;
          font-size: 30px;
          color: white;
        }
        .num {
          display: inline-block;
          font-size: 20px;
          color: white;
        }
      }
      .btn2 {
        box-sizing: border-box;
        margin-right: 18px;
        display: inline-block;
        background-color: #ccecf8;
        padding: 18px 21px;
        border-radius: 10px;
        height: 65px;
        & > :nth-child(1) {
          display: inline-block;
          font-size: 30px;
          color: rgb(7, 17, 27);
        }

        .num {
          display: inline-block;
          font-size: 20px;
          color: rgb(7, 17, 27);
        }
      }
      .btn3 {
        box-sizing: border-box;
        margin-right: 18px;
        display: inline-block;
        background-color: #e9edec;
        padding: 21px;
        border-radius: 10px;
        height: 65px;
        & > :nth-child(1) {
          display: inline-block;
          font-size: 30px;
          color: rgb(7, 17, 27);
        }
        .num {
          display: inline-block;
          font-size: 20px;
          color: rgb(7, 17, 27);
        }
      }
    }
    .choose-tab {
      padding: 36px 0;
      & > :nth-child(1) {
        font-size: 36px;
        color: rgb(147, 153, 159);
        vertical-align: middle;
      }
      & > :nth-child(2) {
        font-size: 28px;
        color: rgb(147, 153, 159);
        display: inline-block;
        margin-left: 15px;
        vertical-align: middle;
      }
    }
  }
  .userComments {
    background-color: white;
    padding: 36px 36px 0;

    .user {
      position: relative;
      & > :nth-child(1) {
        width: 56px;
        height: 56px;
        border-radius: 50%;
        border: 1px solid red;
      }
      & > :nth-child(2) {
        margin-left: 24px;
        display: inline-block;
        .time {
          position: absolute;
          right: 0;
        }
        .star {
          margin-top: 8px;
          margin-right: 12px;
          display: inline-block;
          img {
            width: 24px;
            height: 24px;
            margin-right: 12px;
          }
        }
        & > :nth-child(2) {
          font: size 20px;
          font-weight: 200;
          color: rgb(147, 153, 159);
        }
      }
    }
    .user-comments {
      margin: 12px 84px 16px;
      font-size: 24px;
      color: rgb(7, 17, 27);
      line-height: 36px;
    }
    .praise {
      border-bottom: 1px solid rgba(7, 17, 27, 0.1);
      padding-bottom: 36px;
      margin: 0 84px;
      & > :nth-child(1) {
        font-size: 24px;
        color: rgb(0, 160, 220);
        vertical-align: middle;
      }
      .a {
        color: rgb(7, 17, 27);
      }
      .tag {
        display: inline-block;
        width: 126px;
        height: 32px;
        margin-left: 16px;
        padding: 0 12px;
        font-size: 18px;
        line-height: 32px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        color: rgb(147, 153, 159);
        border-radius: 2px;
        border: 1px solid rgba(7, 17, 27, 0.1);
        vertical-align: middle;
      }
    }
  }
}
</style>